import com.asiainfo.kbisheet.control.ListControl;
import com.asiainfo.kbisheet.model.ListModel;
import com.asiainfo.kbisheet.vo.*;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.utils.ArrayUtil;

private var miShow:ContextMenuItem;
private var miXmlEdit:ContextMenuItem;

[Bindable]
private var listModel:ListModel = ListModel.getInstance();

private var listControl:ListControl = new ListControl();

private function init():void{
	listControl.getAllKbsSheetVOList();
	initContextMenu();
}

private function initContextMenu():void
{				
	miShow = new ContextMenuItem('查看报表',false);
	miXmlEdit = new ContextMenuItem('编辑XML',false);	
	
	var myMenu:ContextMenu = new ContextMenu();
	myMenu.customItems.push(miShow);	
	myMenu.customItems.push(miXmlEdit);
	
	miShow.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,linkHandler);
	miXmlEdit.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,xmlEditHandler);
	
	myMenu.hideBuiltInItems();
	adgList.contextMenu = myMenu;
}

private function linkHandler(event:ContextMenuEvent):void {
	if(adgList.selectedIndex>-1){
		try {
			var url:URLRequest = new URLRequest("kbs.html?sid=" + KbsSheetVO(adgList.selectedItem).sheetId + "&new_menu_id=300630&user_id=2dc4515d0c32ddfe521923994e59f9df42964f64ab2780ac06cbf74992657332a0480ba69aeede3296c5a2ba53e424b31597db43ea3440c27e41148ed0ed86e279f17743e85dbcaefb7420cd364f71edcd7446e8004841b3470161d98dd5fdaa57946d42c7ca5cf91912617fae181245bfbb935650a81a3291e8a9cdb77373c1&user_password=C11D8D6585F9655F816F69E10CE81654");
			navigateToURL(url);
		} catch (e:Error) {
		}
	}
}

private function xmlEditHandler(event:ContextMenuEvent):void {
	if(adgList.selectedIndex>-1){
		try {
			var url:URLRequest = new URLRequest("XmlEdit.swf?sid=" + KbsSheetVO(adgList.selectedItem).sheetId);
			navigateToURL(url);
		} catch (e:Error) {
		}
	}
}

private function newXML():void {
	var url:URLRequest = new URLRequest("NewXML.swf");
	navigateToURL(url);
}

private function formatStart(item:Object,column:AdvancedDataGridColumn):String{
	return dateFormatter.format(item.xmlTime);
}